package client.service;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import client.io.ClientIO;
import domain.action.Action;
import domain.records.MedicalService;
import domain.session.Request;
import domain.session.Response;

public class MedicalServiceService {

	public static List<MedicalService> getAllServices() {
		JSONObject requestJson = new JSONObject();
		ClientIO.sendRequest(new Request(Action.GET_ALL_SERVICES, requestJson));

		Response response = ClientIO.getResponse();
		JSONObject responseJson = response.getResponse();
		JSONArray serviceArray = responseJson.getJSONArray("services");
		
		List<MedicalService> services = new ArrayList<MedicalService>();
		
		for (int i = 0; i < serviceArray.length(); i++) {
			services.add(new MedicalService(serviceArray.getJSONObject(i)));
		}
		
		return services;
	}

}
